package com.mjlf.test_kafka.receiver;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.Optional;

/**
 * @ClassName: KafkaReceiver
 * @Author: majun
 * @CreateDate: 2018/10/30 11:08
 * @Version: 1.0
 * @Description: TODO
 */

@Component
public class KafkaReceiver {

    @KafkaListener(topics = {"test"})
    public void listen(ConsumerRecord<?,?> record){
        Optional<?> kafkaMessage = Optional.ofNullable(record.value());
        if (kafkaMessage.isPresent()) {
            Object message = kafkaMessage.get();

            System.out.println("record =" + record);
            System.out.println("message =" + message);
        }
    }
}
